<?php

include "fonctions.php";
head_html("Proposition de sujet");
en_tete();
?>

	<div id="contenu">
		<?php
			menu_lateral_droit();
		?>
		<div id="texte">
			<?php
			db_connect();

			//Creation en base du cadavre excquis
			if(isset($_POST['validerCadavre'])){
				if (isset($_POST['atelier']) && isset($_POST['name']) && $_POST['name'] != "")
				{
					$Col1_Array = $_POST['atelier']; 
					foreach($Col1_Array as $selectValue){ 
						$req_atelier = "INSERT INTO LMLP.sujet (texte,pseudo,nomAtelier) VALUES (\"".$_POST['name']."\",\"".$_SESSION['idUtil']."\",\"".$selectValue."\");";
						mysql_query($req_atelier) or die (mysql_error());
						echo "<script>
							
						alert(\"Le sujet a été créé pour l'atelier ".$selectValue."\");
						</script>";
	
					}
					echo '<meta http-equiv="refresh" content="1; URL=creation_sujet.php">';
					
					
					
					
					

				
				}else{
					if(!isset($_POST['atelier'])){
						echo "<p class=\"red\">Veuillez s&eacute;lectionner au moins un atelier.</p>";
					}
					
					if(!isset($_POST['name']) || $_POST['name'] == ""){
						echo "<p class=\"red\">Veuillez entrer un nom de cadavre</p>";
					}
					
					
				}
			}
			
			
			echo "<h1>Proposer un sujet</h1>";
			//formulaire pour la creation du cadavre excquis
				$req = "SELECT nomAtelier FROM LMLP.ateliers;";
				$result = mysql_query($req) or die (mysql_error());
				$nb = mysql_num_rows($result);	
				
				
				echo "<form name=\"inscription\" method=\"post\" action=\"creation_sujet.php\">";
				echo"<ul id=\"jeux\">";
				echo "<li>";
				echo "<p>Atelier:";
				echo "<select name=\"atelier[]\" multiple=\"multiple\" required>";
					while ($row = mysql_fetch_assoc($result)) {
						echo "<option value=\"".$row['nomAtelier']."\">".$row['nomAtelier']."</option>";
					}
				echo "</select></p>";
				echo "</li>";
				echo "<li>";
				echo "<p>Nom/Description du sujet";
				echo "<input type=\"text\" name=\"name\"/ required>";
						
				echo "</p>";
				echo "</li>";
				echo"</ul>";
				echo "<p><input type=\"submit\" name=\"validerCadavre\" value=\"Valider Cr&eacute;ation du sujet\"/ ></p>";

				echo "</form>";
				
			?>
				
			
		</div>
	</div>
	<?php
		pied_page();
	?>
</body>
</html>

